<?php
namespace app\beautiful\model\appointment;
use app\common\model\CommonModel;

class TechnicianModel extends CommonModel{
    protected  $name = 'beautiful_technician';
    protected  $pk   = 'technician_id';
    protected $type=[
        'tags'=>'array'
    ];

    public function projects()
    {
        return $this->hasMany(TechnicianProjectModel::class,'technician_id','technician_id');
    }

    public function position(){
        return $this->hasOne(PositionModel::class,'position_id','position_id');

    }

    public function commission(){
        return $this->hasOne(CommonModel::class,'commission_id','commission_id');

    }

    public function getTagsStringAttr($value,$data)
    {
        $tags=json_decode($data['tags'],true);
        if(empty($tags)) return '';
        return implode(',',$tags) ?? '';
    }

    public function getStatusMeansAttr($value,$data)
    {
        $status_means=[
            1=>'在职',
            -1=>'离职',
        ];
        return $status_means[$data['status']] ?? '';
    }

    public function schedulings()
    {
        return $this->hasMany(TechnicianSchedulingModel::class,'technician_id','technician_id');
    }
}
